Subroutine heateq(atemp,ftemp,temp)

	USE ckvar
	
	IMPLICIT NONE
	REAL :: atemp,ftemp,temp
	REAL :: tmx,tmn
	REAL :: hkf,hkair,hreac,heq
	REAL :: err
	INTEGER :: i,j
	
	tmx=max(atemp,ftemp)
	tmn=min(atemp,ftemp)

	CALL calthp(ftemp)
	hkf=hk(1)*nmspc(1)
	CALL calthp(atemp)
	hkair=0.0
	do i=2,nspc
	hkair=hkair+hk(i)*nmspc(i)
	enddo	
	hreac=hkf+hkair

	do i=1,20
	temp=0.5*(tmx+tmn)
	CALL calthp(temp)
	heq=0.0
	do j=1,nspc
	heq=heq+nmspc(j)*hk(j)
	enddo	
	if(hreac.gt.heq) then
	tmn=temp
	else
	tmx=temp
	endif
	err=abs((hreac-heq)/hreac)*100.0
	if(err.le.0.01) go to 20
	enddo
   20	continue
End subroutine
